package router

import (
	"github.com/gogf/gf/errors/gerror"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"github.com/gogf/swagger"
	"shrimp-blog-server/app/api"
	"shrimp-blog-server/middleware"
)

func init() {
	s := g.Server()
	s.BindMiddlewareDefault(middleware.Ctx)
	s.BindMiddlewareDefault(middleware.CORS)
	s.BindMiddlewareDefault(middleware.ErrorHandler)
	s.Group("/api", func(group *ghttp.RouterGroup) {
		group.POST("/login", api.User.Login)
		group.POST("/register", api.User.Register)
		group.REST("/user", api.User)
		group.REST("/article", api.Article)
		group.REST("/comment", api.Comment)
		group.REST("/label", api.Label)
		group.REST("/link", api.Link)
		group.REST("/message", api.Messages)
		group.REST("/navbar", api.Navbar)
		group.REST("/page_template", api.PageTemplate)
		group.REST("/resource", api.Resource)
		group.REST("/sort", api.Sorts)
		group.REST("/subject", api.Subject)
		
	})
	s.Group("/admin", func(group *ghttp.RouterGroup) {
		group.POST("/login", api.User.Login)
		group.REST("/user", api.User)
		group.REST("/article", api.Article)
		group.REST("/comment", api.Comment)
		group.REST("/label", api.Label)
		group.REST("/link", api.Link)
		group.REST("/message", api.Messages)
		group.REST("/navbar", api.Navbar)
		group.REST("/page_template", api.PageTemplate)
		group.REST("/resource", api.Resource)
		group.REST("/sort", api.Sorts)
		group.REST("/subject", api.Subject)
		// 分页查询
		group.GET("/article/page", api.Article.GetListPage)
		group.GET("/label/page", api.Label.GetListPage)
		group.GET("/sort/page", api.Sorts.GetListPage)
		group.GET("/subject/page", api.Subject.GetListPage)
	})
	sw := &swagger.Swagger{
		Info: swagger.SwaggerInfo{
			Title:          "虾米小站api文档",
			Version:        "1.0",
			TermsOfService: "虾米小站",
			Description:    "描述了各个接口如何使用",
		},
		Schemes: []string{"http"},
	}
	err := sw.Install(s)
	if err != nil {
		panic(gerror.Wrap(err, "swagger初始化失败"))
	}
}
